package glazedlists.chapter5;

import ca.odell.glazedlists.matchers.Matcher;
import ca.odell.issuezilla.Issue;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class IssuesForUsersMatcher implements Matcher<Issue> {

    private Set<String> users = new HashSet<>();

    public IssuesForUsersMatcher(Collection<String> users) {
        this.users.addAll(users);
    }

    @Override
    public boolean matches(Issue issue) {
        if (issue == null) {
            return false;
        }
        if (users.isEmpty()) {
            return true;
        }

        String user = issue.getReporter();
        return users.contains(user);
    }
}
